home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / TAWUG / TAWUG Disk No. 56 (SHK) / TAWUG56.shk / LOGO.NOTES (.txt) < prev    next >
AppleWorks Document  |  1987-07-01  |  13KB  |  363 lines

  1. O=====|====|====|====|====|====|====|====|====|====|====|====|====|====|====|===
  2. Page     
  3. PROGRAMMING IN APPLE LOGO
  4. I.  Introduction
  5. @"Logo is a language for computers.  Compared with natural human H
  6. Flanguages like English or French, it has a very small number of words I
  7. Gand grammatical rules.  But Logo can be extended easily.  In fact this J
  8. His what programming in Logo is all about; using what exists to make new A
  9. things, and then using the new things to make more new things."
  10. G"The initial vocabulary words, which we refer to as Logo 
  11. primitives
  12. Ideal with different kinds of computation including familiar ones such as @
  13. >adding and subtracting numbers and less familiar ones such as )
  14. manipulating words and lists of words."
  15. H"A different kind of computation is chosen as the focus of this guide.  F
  16. DTechnically, the area is known as computer graphics.  It has become J
  17. Hfamiliar through computer art, special effects, and video games.  As an K
  18. Iintroductory route into programming, computer graphics has the advantage K
  19. Ithat you can see how your programs work.  Our experience is that this is F
  20. Dan excellent way to develop and intuitive understanding of what all 
  21. programming is about."
  22. ----------------------------------------------------
  23. II.  Starting Logo
  24. ITo start Logo with the computer off, first insert the Apple Logo program K
  25. Idisk, then turn on the Apple power switch.  The disk drive light will go J
  26. Hon.  After a few moments the light will go off, the drive will stop and '
  27. your screen will display the message:
  28. PRESS THE RETURN KEY TO BEGIN
  29. IF YOU HAVE YOUR OWN FILE DISKETTE,"
  30. INSERT IT NOW, THEN PRESS RETURN
  31. HSimply press <Return>  The disk drive will again be active and soon you 
  32. will see:
  33. WELCOME TO LOGO
  34. FThe question mark is a 
  35. prompt
  36. , meaning that the computer is waiting E
  37. Cfor your instructions.  The flashing rectangle is the 
  38. cursor
  39.  and :
  40. indicates where the next character you type will appear.
  41. ----------------------------------------------------
  42. III.  Printing with Logo
  43. HType something into the keyboard, for example type "HELLO THERE".  Then 
  44. press <Return>.
  45. The computer will complain "I DON'T KNOW HOW TO HELLO".
  46. Now type:
  47. PRINT [HELLO THERE]
  48. HBe sure to include the square brackets and press <Return>!  If you make F
  49. Da mistake you may use the left and right arrow keys to correct your K
  50. Ityping BEFORE pressing <Return>.  The <Return> key tells the computer to E
  51. Caccept the line you just typed and act on it.  The computer should H
  52. Frespond by printing your message.  Anything included in [ ] following J
  53. Hthe command PRINT will be printed literally on the screen.  If you omit F
  54. the brackets you will be the error message "I DON'T KNOW HOW TO...."
  55. Try some arithmetic:
  56. PRINT 5 + 5
  57. PRINT 321-123
  58. PRINT 4/2
  59. PRINT 4*2
  60. IThe computer uses the * to indicate multiplication and the / to indicate 
  61. division.
  62. Let's get rid of all this garbage.  Now type:
  63. CLEARTEXT
  64. ----------------------------------------------------
  65. IV.  Procedures
  66. Type the command:   GREET.
  67. The computer responds,  I DON'T KNOW HOW TO GREET.
  68. IWe can store a set of commands in programs called 
  69. procedures
  70. .  In this &
  71. way we can teach Logo 
  72. new commands.
  73. ?TO GREET
  74. >PRINT [HELLO THERE]
  75. >PRINT [BYE NOW]
  76. HBe sure to separate TO and GREET with a space.  Did you notice that the I
  77. prompt changed from a ? to a > when you started defining the procedure?E
  78. CThis is to remind you that you are not entering instructions to be F
  79. Dcarried out right away.  Use the word END to indicate that you have 
  80. finished.  Logo will respond:
  81. GREET DEFINED
  82. Now run this little program by typing:   GREET
  83. This time Logo responds:
  84. HELLO THERE    
  85. BYE NOW
  86. We can have this program run several times successively.  Try:
  87. REPEAT 1000 [GREET]
  88. IIf you wish to stop this procedure press CTRL-G.  You do this by holding ;
  89. down the <CONTROL> key and pressing <G> at the same time.
  90. ----------------------------------------------------
  91. V.  Turtle Graphics
  92. GThe Logo "Turtle" was originally a robot attached to a computer with a H
  93. Flong cable which could draw lines on the floor (covered with paper).  C
  94. Now the Turtle lives within the computer and draws on the screen.
  95. To see the turtle give the command:   SHOWTURTLE
  96. GThe text screen will clear and the Turtle appears as a triangle in the @
  97. center of the screen.  The ? prompt now appears at the bottom.
  98. Try to following commands, one at a time, and watch the results:
  99. FORWARD 50
  100. BACK 25
  101. RIGHT 45
  102. LEFT 45
  103. IThese can be abbreviated to save typing:  Forward = FD, Back = BK, Right F
  104. = RT and Left = LT.  You may also want to remember Clearscreen = CS.
  105. Let's try
  106. FD 50
  107. RT 90
  108. FD 50
  109. RT 90
  110. FD 50
  111. RT 90
  112. FD 50
  113. RT 90
  114. Play with these commands at your leisure.
  115. ITry the commands HT, ST, PU and PD.  What effects do they have?  What do $
  116. you suppose the letters stand for.
  117. ----------------------------------------------------
  118. VI.  The Logo Editor
  119. JThere is another way to define a procedure.  We can use the Logo Editor.  I
  120. GIn this environment typing mistakes can be corrected more easily.  The K
  121. ITurtle drawing screen will be replaced by the Editor screen.  The way to 2
  122. enter the Editor is with the EDIT or ED command.
  123. EDIT "SQUARE
  124. IThe quotation mark preceding the name of the procedure is essential!  If E
  125. Cyou omit this you will get the error message, "I DON'T KNOW HOW TO I
  126. GSQUARE".  Check the bottom of the screen.  Does it say "Logo Editor"?  I
  127. Look at the top of the screen.  It should contain the line "TO SQUARE".
  128. Complete the procedure as follows:
  129. TO SQUARE
  130. FD 50 RT 90
  131. FD 50 RT 90
  132. FD 50 RT 90
  133. FD 50 RT 90
  134. HYou may combine commands on one line.  Separate with a space for easier 
  135. viewing.
  136. You may use these combinations of keys to edit the procedure:
  137. CTRL-B   to go back
  138. CTRL-F   to go forward
  139. Back arrow  to delete
  140. FWhen finished press CTRL-C to define the procedure.  Logo will return ;
  141. you to the text screen with the message "SQUARE DEFINED".
  142. Try the new command by typing:  SQUARE
  143. Type:  RIGHT 45
  144. Then:  SQUARE 
  145. Try:   REPEAT 6 [RT 45 SQUARE]
  146. This could also be made into a procedure:
  147. EDIT "SQUARESTAR
  148. REPEAT 8 [SQUARE RT 45]
  149. CTRL-C
  150. Type CS then SQUARESTAR.
  151. Experiment with the following:
  152. TO FLAG
  153. FD 30
  154. SQUARE
  155. TO CROSS
  156. REPEAT 4 [FLAG RT 90]
  157. TO FLAGBACK
  158. BK 30
  159. TO FLAGS
  160. REPEAT 4 [FLAGBACK RT 90]
  161. TO MANYFLAGS
  162. FLAGS
  163. RT 45
  164. FLAGS
  165. Experiment with the effects of:
  166. CTRL-T  (textscreen)
  167. CTRL-S  (splitscreen)
  168. CTRL-L  (fullscreen)
  169. ----------------------------------------------------
  170. VII.  Saving and Loading
  171. If your own disk is in the drive, you can save your procedures.
  172. Type:  SAVE "SQUARES
  173. All of the procedures are now saved in a file named "SQUARES".
  174. GAt some later time you can then retrieve these procedures and use them 
  175. again without retyping.
  176. Type:  LOAD "SQUARES
  177. To see what is on your disk type:  CATALOG
  178. ----------------------------------------------------
  179. VIII.  Variables
  180. ESuppose that we wanted to draw boxes of different sizes.  Each would A
  181. ?have a different length for its sides.  We could make separate K
  182. Iprocedures for each size box, or we could designate the size of the side I
  183. Gas a variable.  Then all we need to do is tell the procedure what size 
  184. to use for the variable.
  185. EDIT "BOXR :SIDE
  186. IThe colon (:) tells logo that "side" is a variable.  It will then expect ,
  187. a number to be given whenever BOXR is run.
  188. Complete the procedure:
  189. TO BOXR :SIDE
  190. FD :SIDE
  191. RT 90
  192. FD :SIDE
  193. RT 90
  194. FD :SIDE
  195. RT 90
  196. FD :SIDE
  197. RT 90 
  198. CTRL-C
  199. Now run:    
  200. BOXR 10    
  201. BOXR 20    
  202. BOXR 30    
  203. BOXR 40
  204. Try some of these:
  205. TO SQUARES    
  206. BOXR 10    
  207. BOXR 20    
  208. BOXR 30    
  209. BOXR 40
  210. TO DIAMONDS
  211. RT 45
  212. REPEAT 4 [SQUARES RT 90]
  213. TO FLAGR :SIZE
  214. FD :SIZE
  215. BOXR :SIZE
  216. BK :SIZE
  217. TO 6FLAG :SIZE
  218. REPEAT 6 [FLAG :SIZE RT 60]
  219. TO SPINFLAG :SIZE
  220. 6FLAG :SIZE
  221. 6FLAG :SIZE - 20
  222. TO TRIANGLER :SIDE
  223. REPEAT 3 [FD :SIDE RT 120]
  224. TO TRIANGLES
  225. TRIANGLER 10
  226. TRIANGLER 20
  227. TRIANGLER 30
  228. TRIANGLER 40
  229. TO TRISTAR
  230. REPEAT 10 [TRIANGLES RT 36]
  231. TO TREE :SIDE
  232. RT 30 TRIANGLER :SIDE
  233. RT 60 FD :SIDE / 2
  234. LT 90 BK :SIDE / 2
  235. TO TREES    
  236. TREE 30    
  237. TREE 40    
  238. TREE 50
  239. ----------------------------------------------------
  240. VIII.  Circles, Polygons and Arcs
  241. Try these:
  242. REPEAT 360 [FD 1 RT 1]
  243. CIRCLER (right) and CIRCLEL (left) can be used as well.  Try them:
  244. CIRCLER 20
  245. CIRCLER 10
  246. CIRCLEL 20
  247. CIRCLEL 10
  248. Let's make a face, which will include several new component procedures.
  249. TO FACE :SIZE
  250. HEAD :SIZE
  251. EYES :SIZE / 5
  252. MOUTH :SIZE / 5
  253. NOSE :SIZE / 5
  254. TO HEAD :SIZE
  255. PU FD :SIZE
  256. RT 90
  257. PD CIRCLER :SIZE
  258. PU LT 90
  259. BK :SIZE PD
  260. TO EYES :SIZE
  261. LEYE :SIZE
  262. REYE :SIZE
  263. TO LEYE :S
  264. PU LT 90 FD :S PD
  265. CIRCLER :S / 2
  266. PU BK :S RT 90 PD
  267. TO REYE :S
  268. PU RT 90 FD :S PD
  269. CIRCLEL :S / 2
  270. PU BK :S LT 90 PD
  271. TO MOUTH :SIZE
  272. PU BK 2 * :SIZE
  273. RT 90 FD :SIZE / 2
  274. PD BK :SIZE
  275. PU FD :SIZE
  276. LT 90 FD 2 * :SIZE
  277. TO NOSE :S
  278. BK :S
  279. Experiment with variables in polygons:
  280. TO POLY :STEP :ANGLE
  281. FD :STEP
  282. RT :ANGLE
  283. POLY :STEP :ANGLE
  284. Try:   POLY 30 90  or  POLY 30 120  or  POLY 30 60  or  POLY 30 72
  285. We also have arcs at our disposal.  We use ARCR and ARCL.
  286. Experiment with these:
  287. TO PETAL :SIZE
  288. ARCR :SIZE 90 RT 90
  289. ARCR :SIZE 90 RT 90
  290. Try:  PETAL 40  or  PETAL 30*
  291.       REPEAT 8 [PETAL 40 PETAL 30 RT 45]0
  292.       REPEAT 4 [PETAL 30 RT 45 PETAL 40 RT 45]
  293. How about building a swan?
  294. TO SWAN :SIZE
  295. BODY :SIZE 
  296. NECK :SIZE / 2
  297. HEAD :SIZE / 4
  298. TO BODY :SIZE
  299. RT 45
  300. PETAL :SIZE
  301. LT 45
  302. TO NECK :SIZE
  303. LT 45
  304. ARCR :SIZE 90
  305. ARCL :SIZE 90
  306. RT 45
  307. TO HEAD :SIZE
  308. LT 135
  309. PETAL :SIZE
  310. RT 135
  311. ----------------------------------------------------
  312. IX.  Recursion
  313. ?Recursion is Logo's ability to use a procedure within the same D
  314. Bprocedure.  It is the most significant and powerful aspect of the K
  315. Ilanguage.  In the following examples, notice how the procedure SPI calls 
  316. itself in the last line.
  317. TO SPI :STEP :ANGLE :INC
  318. FD :STEP
  319. RT :ANGLE
  320. SPI :STEP + :INC :ANGLE :INC
  321. FTry these and any other combinations you desire.  Remember, this is a 0
  322. loop that will never stop.  Use CTRL-G to end.
  323. SPI 5 90 2
  324. SPI 5 120 2
  325. SPI 5 60 2
  326. SPI 5 144 2
  327. SPI 5 125 2
  328. SPI 5 160 2
  329. SPI 5 75 1
  330. SPI 5 75 2
  331. ----------------------------------------------------
  332. X.  Color and Graphics
  333. GBoth the color of the background and the color of the Turtle's pen can 6
  334. be changed.  The colors are number-coded as follows:
  335. 0 is Black
  336. 1 is White
  337. 2 is Green
  338. 3 is Violet
  339. 4 is Orange
  340. 5 is Blue
  341. Try changing the background with the SETBG command.
  342. TO CB
  343. SETBG 1 WAIT 20
  344. SETBG 2 WAIT 20
  345. SETBG 3 WAIT 20
  346. SETBG 4 WAIT 20
  347. SETBG 5 WAIT 20
  348. SETBG 0 WAIT 20
  349. FThe WAIT command simply tells the computer to pause for the specified 
  350. length of time.
  351. Now try changing the pen color with SETPC.
  352. TO COLORSQUARES    
  353. SETBG 0
  354. SETPC 2 SQUARE
  355. RT 90 SETPC 3 SQUARE
  356. RT 90 SETPC 4 SQUARE
  357. RT 90 SETPC 5 SQUARE
  358. ----------------------------------------------------
  359. This material is excerpted from "Apple Logo, Introduction to I
  360. GProgramming 
  361. through Turtle Graphics", copyright 1982 by Logo Computer 
  362. Systems, Inc.
  363.